// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import axios from 'axios';
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import App from './App'
import router from './router'
import myUtils from '../static/js/myUtils.js'
import globalConfig from '../static/js/globalConfig.js'
import "babel-polyfill";
Vue.prototype.myUtils = myUtils
Vue.prototype.globalConfig = globalConfig
Vue.config.productionTip = false

Vue.use(ElementUI, { size: 'mini' });

router.beforeEach((to, from, next) => {
  
  if (to.meta.requireAuth) {  // 判断该路由是否需要登录权限
      if (localStorage.getItem("ltsh_session_user_token") != null) {  // 通过vuex state获取当前的token是否存在
        next();
      } else {
        console.log('login');
        next({
            path: '/login',
            query: {redirect: to.fullPath}  // 将跳转的路由path作为参数，登录成功后跳转到该路由
        })
      }
  }
  else {
    next();
  }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
